# Contributor: Krassy Boykinov <kboykinov@teamcentrixx.com>
# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=quick-lint-js
pkgver=3.2.0
pkgrel=0
pkgdesc="Language Server to find bugs in JavaScript programs"
url="https://quick-lint-js.com/"
arch="all"
license="GPL-3.0-or-later"
makedepends="cmake ninja"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	$pkgname-emacs::noarch
	$pkgname-neovim::noarch
	$pkgname-vim::noarch
	"
source="
	$pkgname-$pkgver.tar.gz::https://c.quick-lint-js.com/releases/$pkgver/source/quick-lint-js-$pkgver.tar.gz
	"

build() {
	local node_arch
	case "$CARCH" in
		aarch64) node_arch="arm64" ;;
		armhf|armv7) node_arch="arm" ;;
		ppc64le) node_arch="ppc64" ;;
		s390x) node_arch="s390" ;;
		x86) node_arch="ia32" ;;
		x86-64) node_arch="x64";;
	esac

	cmake -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_BUILD_WITH_INSTALL_RPATH=YES \
		-DQUICK_LINT_JS_ENABLE_VSCODE=NO \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DQUICK_LINT_JS_ENABLE_CLI=YES \
		-DQUICK_LINT_JS_NODEJS_OS_ARCH=$node_arch \
		-DQUICK_LINT_JS_INSTALL_LICENSES_DIR="share/licenses/$pkgname" \
		-S . -B build
	ninja -C build
}

check() {
	cd ./build/
	ctest --output-on-failure
}

package() {
	DESTDIR="$pkgdir" ninja -C build install

	# remove unused components
	rm -rf "$pkgdir"/usr/share/powershell
	# identical file in zsh/site-functions, not copied by zsh-completion
	rm -rf "$pkgdir"/usr/share/zsh/vendor-completions
}

emacs() {
	pkgdesc="Emacs plugin for $pkgname"
	install_if="emacs $pkgname=$pkgver-r$pkgrel"

	amove usr/share/emacs
}

neovim() {
	pkgdesc="Neovim plugin for $pkgname"
	install_if="neovim $pkgname=$pkgver-r$pkgrel"

	amove usr/share/nvim
}

vim() {
	pkgdesc="Vim plugin for $pkgname"
	install_if="vim $pkgname=$pkgver-r$pkgrel"

	amove usr/share/vim
}

sha512sums="
7ec0ae41ec0c78b93fc3961c3f28e2e474ec989751f2dceb92314f1c738e9dfc42522416242d23f3de899d0a8cbf986ec52ced65761e9bb1b1be3e5dc3a80a53  quick-lint-js-3.2.0.tar.gz
"
